// 导入Vue Router的相关API
import { ElStep } from "element-plus";
import { createRouter, createWebHashHistory } from "vue-router";

// 定义路由配置数组
const routes = [
  // 主路由（根路径），使用动态导入加载布局容器组件
  {
    path: "/", // 根路径
    name: "latoud-container", // 布局容器路由名称
    component: () => import("@/views/layoud-container.vue"), // 布局容器组件
    redirect: "/home", // 重定向至'/home'路径，加载首页

    // 子路由配置
    children: [
      // 首页路由
      {
        path: "/home",
        name: "home", // 首页路由名称
        component: () => import("../views/Home.vue"), // 加载首页组件
      },

      // 入住登记相关路由及子路由
      {
        path: '/admission',
        name: 'Admission', // 入住登记路由名称
        children: [
          {
            path: 'register',
            name: 'Register', // 床位登记子路由名称
            component: () => import('../views/Admission/Register.vue'), // 加载床位登记子页面组件
          },
          {
            path: 'admissionregister',
            name: 'AdmissionRegister', // 登记子路由名称
            component: () => import('../views/Admission/AdmissionRegister.vue'), // 加载床位登记子页面组件
          },
          {
            path: 'bed_registration',
            name: 'BedRegistration', // 床位登记子路由名称
            component: () => import('../views/Admission/BedRegistration.vue'), // 加载床位登记子页面组件
          },
          {
            path: 'peaceful_care',
            name: 'PeacefulCare', // 安宁照护子路由名称
            component: () => import('../views/Admission/PeacefulCare.vue'), // 加载安宁照护子页面组件
          },
          {
            path: 'admission_newcheckin',
            name: 'AdmissionNewcheckIn', // 新增入住路由名称
            component: () => import('../views/Admission/AdmissionNewcheckIn.vue'), // 加载新增入住页面组件
          },
        ],
      },

      // 评估管理路由
      {
        path: "/assessment",
        name: "Assessment", // 评估管理路由名称
        component: () => import("../views/Assessment.vue"), // 加载评估管理页面组件
      },

      // 在住管理相关路由及其子路由
      {
        path: "/residence_management",
        name: "ResidenceManagement", // 在住管理路由名称
        children: [
          {
            path: "home_management",
            name: "HomeManagement", // 在家管理子路由名称
            component: () =>
              import("../views/ResidenceManagement/HomeManagement.vue"), // 加载在家管理子页面组件
          },
          {
            path: "peaceful_care",
            name: "ResidencePeacefulCare", // 在住安宁照护子路由名称
            component: () =>
              import("../views/ResidenceManagement/PeacefulCare.vue"), // 加载在住安宁照护子页面组件
          },
          {
            path: "nursing_transfer",
            name: "NursingTransfer", // 养转医子路由名称
            component: () =>
              import("../views/ResidenceManagement/NursingTransfer.vue"), // 加载护理转介子页面组件
          },
        ],
      },
      // 照护管理及其子路由
      {
        path: "/care_management",
        name: "CareManagement", // 照护管理路由名称
        component: null, // 若有共享父组件可指定，若无则留空
        children: [
          // 病床护理子路由
          {
            path: "bedside_care",
            name: "BedsideCare", // 病床护理子路由名称
            component: () => import("../views/CareManagement/BedsideCare.vue"), // 加载病床护理子页面组件
          },
        ],
      },
      // 护理管理路由
      {
        path: "/nursing_management",
        name: "NursingManagement", // 护理管理路由名称
        component: () => import("../views/NurseManage/NursingManagement.vue"), // 加载护理管理页面组件
        redirect: "/nursing_management/nursing_plan", // 重定向到护理计划子路由
        children: [
          // 护理计划子路由
          {
            path: "nursing_plan",
            name: "NursingPlan", // 护理计划子路由名称
            component: () => import("../views/NurseManage/NursingPlan.vue"), // 加载护理计划子页面组件
          },
          {
            path: "count_manage",
            name: "countManage", // 账单明细子路由名称
            component: () => import("../views/NurseManage/CountManage.vue"), // 加载账单明细子页面组件
          },
          {
            path: "evaluation_records",
            name: "EvaluationRecords", // 评估记录子路由名称
            component: () =>
              import("../views/NurseManage/EvaluationRecords.vue"), // 加载评估记录子页面组件
          },
          {
            path: "doctor_advice",
            name: "DoctorAdvice", // 医嘱子路由名称
            component: () => import("../views/NurseManage/DoctorAdvice.vue"), // 加载医嘱子页面组件
          },
          {
            path: "nursing_documents",
            name: "NursingDocuments", // 护理文书子路由名称
            component: () =>
              import("../views/NurseManage/NursingDocuments.vue"), // 加载护理文书子页面组件
            children: [
              {
                path: "record_sheet",
                name: "RecordSheet", // 护士记录子路由名称
                component: () =>
                  import(
                    "../views/NurseManage/NursingDocuments/RecordSheet.vue"
                  ), // 加载护士记录子页面组件
              },
              {
                path: "BloodTest",
                name: "BloodTest", // 血糖检测子路由名称
                component: () =>
                  import("../views/NurseManage/NursingDocuments/BloodTest.vue"), // 加载血糖检测子页面组件
              },
              {
                path: "temperature_trend",
                name: "TemperatureTrend", // 体温趋势子路由名称
                component: () =>
                  import(
                    "../views/NurseManage/NursingDocuments/TemperatureTrend.vue"
                  ), // 加载体温趋势子页面组件
              },
            ],
          },
        ],
      },

      // 医疗护理路由
      {
        path: "/medical_care",
        name: "MedicalCare", // 医疗护理路由名称
        component: () => import("../views/MedicalCare.vue"), // 加载医疗护理页面组件
      },
      // 设备管理路由
      {
        path: "/equipment_management",
        name: "EquipmentManagement", // 设备管理路由名称
        component: () => import("../views/EquipmentManagement.vue"), // 加载设备管理页面组件
      },
      // 排班管理相关路由及其子路由
      {
        path: "/scheduling_management",
        name: "SchedulingManagement", // 排班管理路由名称
        children: [
          {
            path: "nursing_shift_record",
            name: "NursingShiftRecord", // 护理值班记录子路由名称
            component: () =>
              import("../views/SchedulingManagement/NursingShiftRecord.vue"), // 加载护理班次记录子页面组件
          },
          {
            path: "nursing_handover",
            name: "NursingHandover", // 护理交接班子路由名称
            component: () =>
              import("../views/SchedulingManagement/NursingHandover.vue"), // 加载护理交接子页面组件
          },
          {
            path: "nurse_handover",
            name: "NurseHandover", // 护士交接子路由名称
            component: () =>
              import("../views/SchedulingManagement/NurseHandover.vue"), // 加载护士交接子页面组件
          },
          {
            path: "nurse_shift_record",
            name: "NurseShiftRecord", // 护士班次记录子路由名称
            component: () =>
              import("../views/SchedulingManagement/NurseShiftRecord.vue"), // 加载护士班次记录子页面组件
          },
        ],
      },

      // 餐饮管理模块路由及其子路由
      {
        path: "/catering_management",
        name: "CateringManagement", // 餐饮管理路由名称
        children: [
          {
            path: "order_register",
            name: "OrderRegister", // 报餐送餐订单登记子路由名称
            component: () =>
              import("../views/CateringManagement/OrderRegister.vue"), // 加载订单登记子页面组件
          },
          {
            path: "reporting",
            name: "Reporting", // 餐饮报表子路由名称
            component: () =>
              import("../views/CateringManagement/Reporting.vue"), // 加载报表子页面组件
          },
        ],
      },

      // 财务管理模块路由
      {
        path: "/finance_management",
        name: "FinanceManagement", // 财务管理路由名称
        component: () => import("../views/FinanceManagement.vue"), // 加载财务管理页面组件
        children: [
          // 财务管理首页
          {
            path: "",
            component: () =>
              import("../views/FinanceManagement/FinanceHomePage.vue"),
          },
          // 财务管理首页
          {
            path: "/financehomepage",
            name: "FinanceHomePage",
            component: () =>
              import("../views/FinanceManagement/FinanceHomePage.vue"),
          },
          // 账单明细
          {
            path: "/billdetails",
            name: "BillDetails",
            component: () =>
              import("../views/FinanceManagement/BillDetails.vue"),
          },
          // 结算
          {
            path: "/settlementlist",
            name: "SettlementList",
            component: () =>
              import(
                "../views/FinanceManagement/settlement/SettlementList.vue"
              ),
          },
          // 扣费
          {
            path: "/deduction",
            name: "Deduction",
            component: () =>
              import("../views/FinanceManagement/settlement/Deduction.vue"),
          },
          {
            path: "1allcount",
            name: "1allcount",
            component: () => import("../views/FinanceManagement/1AllCount.vue"), // 现况结算},
          },
          {
            path: "2nowinoutcount",
            name: "2nowinoutcount",
            component: () =>
              import("../views/FinanceManagement/2NowInoutcount.vue"), // 现款收支明细},
          },
          {
            path: "3readycount",
            name: "3readycount",
            component: () =>
              import("../views/FinanceManagement/3ReadyCount.vue"), // 预交金收支清单},
          },
          {
            path: "4refundment",
            name: "4refundment",
            component: () =>
              import("../views/FinanceManagement/4Refundment.vue"), // 结算退补清单},
          },
          {
            path: "5reservement",
            name: "5reservement",
            component: () =>
              import("../views/FinanceManagement/5Reservement.vue"), // 医疗储备金消费明细},
          },
          {
            path: "6oldcostcount",
            name: "6oldcostcount",
            component: () =>
              import("../views/FinanceManagement/6OldCostcount.vue"), // 长者费用统计表},
          },
          {
            path: "7acountpayment",
            name: "7acountpayment",
            component: () =>
              import("../views/FinanceManagement/7Acountpayment.vue"), // 账户交易记录},
          },
          {
            path: "8workcountment",
            name: "8workcountment",
            component: () =>
              import("../views/FinanceManagement/8WorkCountment.vue"), // 工作链统计表},
          },
          {
            path: 'payment',
            name: 'Payment',
            component: () => import('../views/FinanceManagement/PayMent.vue')
          }
        ],
      },
      {
        path: "/finanicialStatement",
        component: () =>
          import("../views/FinanceManagement/finanicialStatement.vue"),
      },

      // 床位管理模块路由
      {
        path: "/bed_management",
        name: "BedManagement", // 床位管理路由名称
        component: () => import("../views/BedManagement.vue"), // 加载床位管理页面组件
      },
      // 档案管理模块路由
      {
        path: "/archive_management",
        name: "ArchiveManagement", // 档案管理路由名称
        // component: () => import('../views/ArchiveManagement.vue'), // 加载档案管理页面组件
        children: [
          {
            path: "/notice",
            component: () =>
              import("../views/ArchiveManagement/notice/notice.vue"),
            name: "notice",
            children: [
              {
                path: "/notice/hospitalAppForm",
                component: () =>
                  import(
                    "../views/ArchiveManagement/notice/hospitalAppFor.vue"
                  ),
                name: "hospitalAppForm",
              },
              {
                path: "/notice/leaveReqNotice",
                component: () =>
                  import(
                    "../views/ArchiveManagement/notice/leaveReqNotice.vue"
                  ),
                name: "leaveReqNotice",
              },
              {
                path: "/notice/paymentCon",
                component: () =>
                  import("../views/ArchiveManagement/notice/paymentCon.vue"),
                name: "paymentCon",
              },
              {
                path: "/notice/vacancyOfNotice",
                component: () =>
                  import(
                    "../views/ArchiveManagement/notice/vacancyOfNotice.vue"
                  ),
                name: "vacancyOfNotice",
              },
              {
                path: "/notice/accidentRisk",
                component: () =>
                  import("../views/ArchiveManagement/notice/accidentRisk.vue"),
                name: "accidentRisk",
              },
              {
                path: "/notice/disclaimer",
                component: () =>
                  import("../views/ArchiveManagement/notice/disclaimer.vue"),
                name: "disclaimer",
              },
              {
                path: "/notice/riskNotice",
                component: () =>
                  import("../views/ArchiveManagement/notice/riskNotice.vue"),
                name: "riskNotice",
              },
              {
                path: "/notice/protectNotice",
                component: () =>
                  import("../views/ArchiveManagement/notice/protectNotice.vue"),
                name: "protectNotice",
              },
              {
                path: "/notice/first",
                component: () =>
                  import("../views/ArchiveManagement/notice/first.vue"),
                name: "first",
              },
            ],
          },
          {
            path: "/assessmentRecords",
            component: () =>
              import("../views/ArchiveManagement/assessmentRecords.vue"),
            name: "assessmentRecords",
          },
          {
            path: "/billInformation",
            component: () =>
              import(
                "../views/ArchiveManagement/billInformation/billInformation.vue"
              ),
            name: "billInformation",
            children: [
              {
                path: "/billInformation/personBill",
                component: () =>
                  import(
                    "../views/ArchiveManagement/billInformation/personBill.vue"
                  ),
                name: "personBill",
              },
              {
                path: "/billInformation/medicalBill",
                component: () =>
                  import(
                    "../views/ArchiveManagement/billInformation/medicalBill.vue"
                  ),
                name: "medicalBill",
              },
            ],
          },
        ],
      },
      {
        path: "/notice",
        component: () => import("../views/ArchiveManagement/notice/notice.vue"),
        name: "notice",
        children: [
          {
            path: "/notice/hospitalAppForm",
            component: () =>
              import("../views/ArchiveManagement/notice/hospitalAppFor.vue"),
            name: "hospitalAppForm",
          },
          {
            path: "/notice/leaveReqNotice",
            component: () =>
              import("../views/ArchiveManagement/notice/leaveReqNotice.vue"),
            name: "leaveReqNotice",
          },
          {
            path: "/notice/paymentCon",
            component: () =>
              import("../views/ArchiveManagement/notice/paymentCon.vue"),
            name: "paymentCon",
          },
          {
            path: "/notice/vacancyOfNotice",
            component: () =>
              import("../views/ArchiveManagement/notice/vacancyOfNotice.vue"),
            name: "vacancyOfNotice",
          },
          {
            path: "/notice/accidentRisk",
            component: () =>
              import("../views/ArchiveManagement/notice/accidentRisk.vue"),
            name: "accidentRisk",
          },
          {
            path: "/notice/disclaimer",
            component: () =>
              import("../views/ArchiveManagement/notice/disclaimer.vue"),
            name: "disclaimer",
          },
          {
            path: "/notice/riskNotice",
            component: () =>
              import("../views/ArchiveManagement/notice/riskNotice.vue"),
            name: "riskNotice",
          },
          {
            path: "/notice/protectNotice",
            component: () =>
              import("../views/ArchiveManagement/notice/protectNotice.vue"),
            name: "protectNotice",
          },
          {
            path: "/notice/first",
            component: () =>
              import("../views/ArchiveManagement/notice/first.vue"),
            name: "first",
          },
        ],
      },
      {
        path: "/dang",
        name: "da",
        component: () => import("../views/ArchiveManagement/ArchireDang.vue"),
        children: [
          {
            path: "/zhu",
            name: "z", // 档案管理路由名称
            component: () =>
              import("../views/ArchiveManagement/ArchireManagzhu.vue"),
            // 加载档案管理页面组件
          },
          {
            path: "/ji",
            name: "ben",
            component: () => import("../views/ArchiveManagement/ArchireJi.vue"),
          },
          {
            path: "/jian",
            name: "kang",
            component: () =>
              import("../views/ArchiveManagement/ArchireJian.vue"),
          },
          {
            path: "/hu",
            name: "zhao",
            component: () => import("../views/ArchiveManagement/ArchireHu.vue"),
          },
          {
            path: "/can",
            name: "yin",
            component: () =>
              import("../views/ArchiveManagement/ArchireCan.vue"),
          },
          {
            path: "/feng",
            name: "fe",
            component: () =>
              import("../views/ArchiveManagement/ArchireFeng.vue"),
          },
          {
            path: "/xin",
            name: "xi",
            component: () =>
              import("../views/ArchiveManagement/ArchireXin.vue"),
          },
          {
            path: "/bian",
            name: "b",
            component: () =>
              import("../views/ArchiveManagement/ArchireBian.vue"),
          },
          {
            path: "/jilu",
            name: "j",
            component: () =>
              import("../views/ArchiveManagement/ArchireJilu.vue"),
          },
          {
            path: "/jc",
            name: "c",
            component: () => import("../views/ArchiveManagement/ArchireJc.vue"),
          },
          {
            path: "/qs",
            name: "s",
            component: () => import("../views/ArchiveManagement/ArchireQs.vue"),
          },
        ],
      },

      // 质控管理模块路由及其子路由
      {
        path: "/quality_control",
        name: "QualityControl", // 质控管理路由名称
        children: [
          {
            path: "incident",
            name: "Incident", // 不良事件子路由名称
            component: () => import("../views/QualityControl/Incident.vue"), // 加载事件子页面组件
          },
          {
            path: "satisfaction_survey",
            name: "SatisfactionSurvey", // 满意度调查子路由名称
            component: () =>
              import("../views/QualityControl/SatisfactionSurvey.vue"), // 加载满意度调查子页面组件
          },
          {
            path: "data_reporting",
            name: "DataReporting", // 数据填报子路由名称
            component: () =>
              import("../views/QualityControl/DataReporting.vue"), // 加载数据上报子页面组件
          },
          {
            path: "quality_evaluation_criteria",
            name: "QualityEvaluationCriteria", // 质量评价标准子路由名称
            component: () =>
              import("../views/QualityControl/QualityEvaluationCriteria.vue"), // 加载质量评价标准子页面组件
          },
        ],
      },

      // 系统管理相关路由及其子路由
      {
        path: "/system_management",
        name: "SystemManagement", // 系统管理路由名称
        children: [
          {
            path: "system_users",
            name: "SystemUsers", // 系统用户子路由名称
            component: () =>
              import("../views/SystemManagement/SystemUsers.vue"), // 加载系统用户子页面组件
          },
          {
            path: "permission_management",
            name: "PermissionManagement", // 权限管理子路由名称
            component: () =>
              import("../views/SystemManagement/PermissionManagement.vue"), // 加载权限管理子页面组件
          },
          // {
          //   path: 'module_management',
          //   name: 'ModuleManagement', // 模块管理子路由名称
          //   component: () => import('../views/SystemManagement/ModuleManagement.vue'), // 加载模块管理子页面组件
          // },
          // {
          //   path: 'data_dictionary',
          //   name: 'DataDictionary', // 数据字典子路由名称
          //   component: () => import('../views/SystemManagement/DataDictionary.vue'), // 加载数据字典子页面组件
          // },
          // {
          //   path: 'attribute_configuration',
          //   name: 'AttributeConfiguration', // 属性配置子路由名称
          //   component: () => import('../views/SystemManagement/AttributeConfiguration.vue'), // 加载属性配置子页面组件
          // },
          {
            path: "institution_management",
            name: "InstitutionManagement", // 机构管理子路由名称
            component: () =>
              import("../views/SystemManagement/InstitutionManagement.vue"), // 加载机构管理子页面组件
          },
        ],
      },
    ],
  },
  // 登录
  {
    path: "/login",
    name: "login",
    component: () => import("../views/Login.vue"),
  },
  // 忘记密码
  {
    path: "/forget_password",
    name: "forget_password",
    component: () => import("../views/Forget.vue"),
  },
  {
    path:'/paymentView',
    name:'paymentView',
    component:()=>import('../views/PaymentView.vue')
  }
];

// 创建并配置Vue Router实例
const router = createRouter({
  history: createWebHashHistory(), // 使用哈希历史模式
  routes, // 导入定义好的路由配置数组
});

router.beforeEach((to, from, next) => {
  if (to.name === "login") next();
  let token = localStorage.getItem("accessToken");
  if (!token && to.name !== "login") {
    next({ name: "login" });
  }
  next();
});

// 导出Vue Router实例供全局使用
export default router;
